home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / searchtools / getobjs < prev    next >
Text File  |  1994-08-01  |  3KB  |  116 lines

  1. #! /bin/sh
  2. #      ~4Dgifts/toolbox/searchtools/getobjs library function INDEX creator
  3. #
  4.  
  5. if [ $# -lt 1 ]
  6. then echo Usage: $0 topdirectory; exit 1
  7. fi
  8.  
  9. if [ ! -d $1 ]
  10. then echo Usage: $0 topdirectory "(\"$1\" is not a directory)"; exit 1
  11. fi
  12.  
  13. # Create an index to be used by the 'look' program that does a binary
  14. # search on the first field (should be used with the -f (case insensitve)
  15. # option.  The output file is called "INDEX", and # is placed in the
  16. # current directory.
  17.  
  18. # used to create an index of programs/files that use 'interesting'
  19. # functions that people might want to look at as examples
  20.  
  21. # See the references to '$HOME/skipfuncs' for the method of
  22. # eliminating uninteresting functions
  23.  
  24. # with relocatable objects (.o's), we can figure out which file
  25. # referenced what.  With binaries (programs, dynamic executables)
  26. # we can't tell which file that went into it used it, so we
  27. # make 2 passes, one for each kind, with a slightly different
  28. # sed script.  Of course, with .o's, the externals may be
  29. # elsewhere in the same program.  That's life.  The other disadvantage
  30. # with the .o's is that we lose the full pathname, since we get the
  31. # name of the original file out of the header.  But we have a hack
  32. # for that also!
  33.  
  34. # so if the filename doesn't have a suffix (.c, .c++, etc.), then
  35. # it is the executable, and you may have to look at the Makefile
  36. # to see which files to check, but this is seldom much of a problem.
  37.  
  38. # this prepends the filename to each object
  39. # ANSI 'reserved for system use' names like __stuff or _ABC are skipped.
  40. # The final substitute, ending with 'p', reverses the fields.
  41.  
  42. trap "rm /usr/tmp/DTlist$$ /tmp/sed*$$" 0 1 2 15
  43.  
  44. cat > /tmp/sed.ex$$ << \EOF
  45. /:$/h
  46. /][     ]*_[_A-Z]/d
  47. /^\[.* FUNC  *UNDEF/ {
  48. H
  49. x
  50. s/\n.*][     ]*/ /
  51. s/[     0][     0x].*//
  52. s/\(.*\): \(.*\)/\2    \1/p
  53. s/.*    //
  54. s/[^:]$/&:/
  55. h
  56. }
  57. EOF
  58.  
  59. cat > /tmp/sed.rel$$ << \EOF
  60. /:$/h
  61. /Text.*File/ {
  62. /\/usr\/include\//d
  63. s/^\[.*][     ]*//
  64. s/[     0].*/:/
  65. /\.h:/d
  66. s,/,,g
  67. x
  68. s/[^/]*://
  69. x
  70. H
  71. x
  72. s/\n//
  73. h
  74. }
  75. /][     ]*_[_A-Z]/d
  76. /^\[.* Undefined[     ]*Proc/ {
  77. H
  78. x
  79. s/\n.*][     ]*/ /
  80. s/[     0][     0x].*//
  81. s/\(.*\): \(.*\)/\2    \1/p
  82. s/.*    //
  83. s/[^:]$/&:/
  84. h
  85. }
  86. EOF
  87.  
  88. # the c++filt demangles c++ names (and fortunately leaves intact
  89. # the stuff after the white space); then we have to eliminate the
  90. # stuff that it adds, when it demangles.
  91. find $* -type f -follow -print | xargs file | \
  92.     sed -n '/dynamic executable/s/:.*//p' | \
  93.     xargs elfdump -Dt | \
  94.     sed -n -f /tmp/sed.ex$$ | \
  95.     /usr/lib/c++/c++filt | \
  96.     sed -e 's/.*::\([^:]*\)(/\1(/' -e 's/(.*)//' -e '/^~/d' > /usr/tmp/DTlist$$
  97.  
  98. find $* -type f -follow -print | xargs file | \
  99.     sed -n '/relocatable/s/:.*//p' | \
  100.     xargs odump -vt | \
  101.     sed -n -f /tmp/sed.rel$$ | \
  102.     /usr/lib/c++/c++filt | \
  103.     sed -e 's/.*::\([^:]*\)(/\1(/' -e 's/(.*)//' -e '/^~/d' -e 's,,/,g' \
  104.         -e s,/\./,/,g >> /usr/tmp/DTlist$$
  105.  
  106. # Can add another sed here to eliminate functions like ioctl that
  107. # we don't want to see.  For now, assume that if the file $HOME/skipfuncs
  108. # exists, that we should eliminate those functions.  It should consist
  109. # of lines like (where it is a space and a tab inside the brackets)
  110. # /^ioctl[     ]/d'
  111.  
  112. if [ -r $HOME/skipfuncs ]
  113. then sed -f $HOME/skipfuncs /usr/tmp/DTlist$$ | sort -u -o /usr/tmp/INDEX
  114. else sort -u /usr/tmp/DTlist$$ -o /usr/tmp/INDEX
  115. fi
  116.